package com.yin.myproject;

import java.util.concurrent.TimeUnit;

/**
 * @author Eason
 * @create 2018-04-01 16:05
 **/
public class VolatileTest {
    public static volatile int race = 0;

    public static void increase() {
        race++;
    }


    public static final int THREAD_CONT = 20;

    public static void main(String[] args) throws InterruptedException {
        Thread[] threads = new Thread[THREAD_CONT];
        for (int i = 0; i < THREAD_CONT; i++) {
            threads[i] = new Thread(() -> {
                for (int i1 = 0; i1 < 10000; i1++) {
                    increase();
                }
            });
            threads[i].start();
        }
        TimeUnit.SECONDS.sleep(20);
        System.out.println(race);
    }
}
